//
//  BagNumView.m
//  New_Runway
//
//  Created by mack on 2018/3/29.
//  Copyright © 2018年 NelsonJ. All rights reserved.
//

#import "BagNumView.h"

@implementation BagNumView
{
    
    UILabel *_numLabel;
    int _jumpNum;
    NSTimer *_jumpTimer;
}
+(BagNumView *)showRedPointAndUnreadNumberViewWithCenterPoint:(CGPoint)point{
    
    return [[BagNumView alloc] initWithFrame:CGRectMake(point.x - 10, point.y - 7, 10, 10)];;
}

+(BagNumView *)showRedPointAndUnreadNumberViewWithLeftPoint:(CGPoint)point{
    
    
    return  [[BagNumView alloc] initWithFrame:CGRectMake(point.x, point.y + 3, 20, 20)];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        _backGroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
        _backGroundView.backgroundColor = MAIN_FONT_COLOR();
        _backGroundView.clipsToBounds = YES;
        _backGroundView.layer.cornerRadius = 10;
        _backGroundView.hidden = YES;
        [self addSubview:_backGroundView];
        
        _numLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.width,20)];
        [_numLabel setFont:[UIFont boldSystemFontOfSize:13]];
        [_numLabel setTextColor:[UIColor whiteColor]];
        [_numLabel setTextAlignment:NSTextAlignmentCenter];
        _numLabel.hidden = YES;
        [self addSubview:_numLabel];
        
    }
    return self;
}

-(void)setNumber:(NSInteger)number{
    
    _number = number;
    if (_number > 99) {
        _number = 99;
        _numLabel.text = [NSString stringWithFormat:@"%lu+",(long)_number];
    }else{
        _numLabel.text = [NSString stringWithFormat:@"%lu",(long)_number];
    }
    [self updateBackgroundView];
    
}


-(void)updateBackgroundView{
    
    if (_number < 1) {
        _numLabel.hidden = YES;
        _backGroundView.hidden = YES;
    }else if (_number == 99) {
            CGRect newRect = CGRectMake(0, 0, 29, 20);
           [_numLabel setFrame:CGRectMake(0, 0, newRect.size.width, 20)];
            [_backGroundView setFrame:newRect];
            _backGroundView.hidden = NO;
            _numLabel.hidden = NO;
        
        }
        else
        {
            CGRect newRect = CGRectMake(0, 0, 20, 20);
            [_numLabel setFrame:CGRectMake(0, 0, newRect.size.width, 20)];
            [_backGroundView setFrame:newRect];
            _backGroundView.hidden = NO;
            _numLabel.hidden = NO;
           
            
        }
    
}


@end
